<template>
  <el-row type="flex" class="time-flow-content">
    <el-timeline class="time-flow-line-wrapper">
      <template v-for="(item, index) in flow">
        <el-timeline-item
          v-if="
            !['candidate', 'sequenceFlow'].includes(item.historyActivityType)
          "
          :type="index == flow.length - 1 ? 'primary' : ''"
          :key="item.id"
        >
          <div class="time-flow-top">
            <span>{{
              item.historyActivityType == "endEvent"
                ? "结束"
                : item.historyActivityName || "未命名"
            }}</span>
            <span>{{
              parseTime(item.endTime) || parseTime(item.createTime)
            }}</span>
          </div>
          <div class="time-flow-des-wrapper">
            <p>
              {{ item.assigneeName }} 在 [{{ parseTime(item.createTime) }}]
              开始处理 [{{
                item.historyActivityType == "endEvent"
                  ? "结束"
                  : item.historyActivityName || "未命名"
              }}] 环节
            </p>
            <p v-if="item.historyActivityDurationTime">
              任务历时 [{{ item.historyActivityDurationTime }}]
            </p>
            <template v-if="item.comments && item.comments.length > 0">
              <p
                v-for="(comment, index) in item.comments.filter(
                  (c) => c.action === 'AddComment'
                )"
                :key="index"
              >
                <template v-if="index < 1">
                  <span v-if="commentMap[comment.type]"
                    >{{ commentMap[comment.type] }}: [{{
                      comment.fullMessage
                    }}]</span
                  >
                  <span
                    style="color: #1989fa; float: right"
                    v-if="
                      item.comments.filter((c) => c.action === 'AddComment')
                        .length > 1
                    "
                    @click="handleClick"
                    >{{ toggleText }}
                    <i
                      :class="[
                        isFlag ? 'el-icon-arrow-up' : 'el-icon-arrow-down',
                      ]"
                    ></i>
                  </span>
                  <p style="color: gray; font-size: 12px" v-if="comment.time">
                    {{ parseTime(comment.time) }}
                  </p>
                </template>
                <template v-if="index > 0 && isFlag">
                  <span v-if="commentMap[comment.type]"
                    >{{ commentMap[comment.type] }}: [{{
                      comment.fullMessage
                    }}]</span
                  >
                  <p style="color: gray; font-size: 12px" v-if="comment.time">
                    {{ parseTime(comment.time) }}
                  </p>
                </template>
              </p>
              <template v-if="item.attachments && item.attachments.length > 0">
                <p style="display: flex; align-items: baseline">
                  附件:
                  <avue-upload
                    :value="item.attachments"
                    :props="{ label: 'name', value: 'url' }"
                    :upload-preview="handleUploadPreview"
                    disabled
                  ></avue-upload>
                </p>
              </template>
            </template>
            <p v-if="item.endTime">结束时间: [{{ parseTime(item.endTime) }}]</p>
          </div>
        </el-timeline-item>
      </template>
    </el-timeline>
  </el-row>
</template>

<script>
import exForm from "../../mixins/ex-form";
export default {
  name: "wf-flow",
  mixins: [exForm],
  props: {
    flow: {
      type: Array,
      default: () => {
        return [];
      },
    },
  },
  data() {
    return {
      isFlag: false,
      toggleText: "展开",
      commentMap: {
        assigneeComment: "变更审核人",
        dispatchComment: "调度",
        transferComment: "转办",
        delegateComment: "委托",
        rollbackComment: "驳回意见",
        terminateComment: "终止意见",
        addMultiInstanceComment: "加签",
        deleteMultiInstanceComment: "减签",
        withdrawComment: "撤销",
        recallComment: "撤回",
        deleteProcessComment: "删除流程",
        comment: "审批意见",
      },
    };
  },
  methods: {
    handleClick() {
      this.isFlag = !this.isFlag;
      this.toggleText = this.isFlag ? "收起" : "展开";
    },
  },
};
</script>

<style lang="scss" scoped>
.time-flow-content {
  width: 45%;
  .time-flow-line-wrapper {
    width: 100%;
    .time-flow-top {
      font-size: 16px;
      font-family: PingFangSC-Regular, PingFang SC;
      font-weight: 400;
      color: #333333;
      line-height: 20px;
      margin-bottom: 15px;
      span {
        &:first-child {
          margin-right: 18px;
        }
        &:last-child {
          font-size: 14px;
          color: #777777;
        }
      }
    }
    .time-flow-des-wrapper {
      padding: 26px 32px;
      background: #f2f5f8;
      color: #333;
    }
  }
}
</style>
